package com.jtpay.unionpay.product.utils;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import com.jtpay.unionpay.product.R;


/**
 * Created by Administrator on 2018/1/15.
 */

public class ProgressDialogUtil {
    private Dialog mDialog;

    /**
     * 显示ProgressDialog
     */
    public void showProgress(Context context, String msg) {
        try {
            mDialog = show(context, msg);
        } catch (Exception e) {
            LogUtil.log(e.getMessage());
        }
    }

    private Dialog show(Context context, String message) {
        return ProgressDialog.show(context, null, message, false, false);
    }

    public boolean isShowing() {
        return mDialog != null && mDialog.isShowing() ? true : false;
    }

    /**
     * 显示ProgressDialog
     */
    public void showProgress(Context context) {
        try {
            if (mDialog == null) {
                mDialog = show(context, null);
            }
            if (mDialog != null && !mDialog.isShowing()) {
                mDialog.show();
            }
        } catch (Exception e) {
            LogUtil.log(e.getMessage());
        }
    }

    /**
     * 显示ProgressDialog
     */
    public void showDefProgress(Context context) {
        try {
            if (mDialog == null) {
                mDialog = show(context, context.getResources().getString(R.string.progress_tips_def));
            }
            if (mDialog != null && !mDialog.isShowing()) {
                mDialog.show();
            }
        } catch (Exception e) {
            LogUtil.log(e.getMessage());
        }
    }

    /**
     * 取消ProgressDialog
     */
    public void dismissProgress() {
        try {
            if (mDialog != null && mDialog.isShowing()) {
                mDialog.dismiss();
            }
        } catch (Exception e) {

        }

    }
}
